package com.example.HelloSpace;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.HelloSpace.service.AlarmService;
import com.google.android.material.button.MaterialButton;

public class AlarmActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm);
        // 设置关闭按钮的点击事件
        MaterialButton closeButton = findViewById(R.id.btn_close);
        closeButton.setOnClickListener(v -> {
            // 停止闹钟声音和释放电源锁
            stopService(new Intent(this, AlarmService.class));
            PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "MyApp:AlarmWakelock");
            wakeLock.release();
            finish(); // 关闭当前Activity
        });
    }
}
